﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Medical.Business;
using System.Data;

public partial class Search : WebPage
{

    protected int nPageIndex = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["page"] != null)
            {
                nPageIndex = Convert.ToInt32(Request.QueryString["page"]);
            }
            InitList();
        }
    }


    /// <summary>
    /// 获取列表
    /// </summary>
    protected void InitList()
    {
        string strName = Server.HtmlEncode(Server.UrlDecode(Common.GetQueryValue("key", 0)));
        anpPage.EnableUrlRewriting = true;
        anpPage.UrlRewritePattern = @"~/search/?key=" + Common.GetQueryValue("key", 0) + "&page={0}";
        if (string.IsNullOrEmpty(strName))
        {
            ltlPageUrl.Text = "所有文章";
        }
        else
        {
            ltlPageUrl.Text = "查询："+strName;
            SetPageInfo(strName+"_" + strWebTitle, string.Empty, string.Empty);
        }
        int nRecordCount = 0;
        int nPageCount = 0;
        //文章信息列表绑定
        DataTable dt = new BisArticle().GetAllArticleList(strName,nPageIndex, anpPage.PageSize, ref nPageCount, ref nRecordCount);
        anpPage.RecordCount = nRecordCount;
        rptArticle.DataSource = dt;
        rptArticle.DataBind();
        dt.Dispose();
    }

    /// <summary>
    /// 列表绑定处理
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void rptArticle_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DataTable dtSort = (DataTable)((Repeater)sender).DataSource;
        Literal ltlInfo = e.Item.FindControl("ltlInfo") as Literal;
        string strInfo = strInfo = Common.NoHTML(dtSort.Rows[e.Item.ItemIndex]["Info"].ToString());
        ltlInfo.Text = (strInfo.Length > 80 ? strInfo.Substring(0, 80) : strInfo) + "…";
    }
}